package main

import (
	"fmt"
	"github.com/gotk3/gotk3/gdk"
	"github.com/gotk3/gotk3/glib"
	"github.com/gotk3/gotk3/gtk"
	"os"
)

func main() {
	const appId = "com.lizk.app"

	app, _ := gtk.ApplicationNew(appId, glib.APPLICATION_FLAGS_NONE)
	app.Connect("activate", func() {
		onActivate(app)
	})
	app.Run(os.Args)
}

func onActivate(app *gtk.Application) {
	appWindow, _ := gtk.ApplicationWindowNew(app)
	appWindow.SetTitle("Grid example")
	//-- 以上，通常的代码输入完了，接下就是这个例子的重点了:-D

	appWindow.SetDefaultSize(200, 200)
	file, _ := gdk.PixbufNewFromFile("C:\\work\\文档\\tmp\\头像.png")
	appWindow.SetIcon(file)

	grid, _ := gtk.GridNew() //创建容器

	//appWindow.Add(grid)     //将容器添加到window中

	//现在再让我们创建一些按钮来展示grid的效果
	button1, _ := gtk.ButtonNewWithLabel("Button 1")
	button2, _ := gtk.ButtonNewWithLabel("Button 2")
	button3, _ := gtk.ButtonNewWithLabel("Button 3")
	button3.Connect("clicked", func() {
		messageDialogNew := gtk.MessageDialogNew(appWindow, gtk.DIALOG_MODAL, gtk.MESSAGE_INFO, gtk.BUTTONS_NONE, "你点我就出来")

		okButton, _ := messageDialogNew.AddButton("确定", gtk.RESPONSE_OK)
		cancelButton, _ := messageDialogNew.AddButton("取消", gtk.RESPONSE_CANCEL)

		okButton.Connect("clicked", func() {
			fmt.Println("点击了确定按钮")
			messageDialogNew.Destroy()
		})
		cancelButton.Connect("clicked", func() {
			fmt.Println("点击了取消按钮")
			messageDialogNew.Destroy()
		})
		messageDialogNew.Show()
	})
	//将buttons添加到grid中
	grid.Attach(button1, 0, 1, 1, 1) //参数：左,上,宽,高
	grid.Attach(button2, 9, 1, 1, 1)
	grid.Attach(button3, 0, 2, 2, 1)
	//-- 注意一下，按钮的位置就像在一个坐标轴中，原点在左上，x轴向右，y轴向下
	//-- 如果你不是很喜欢或者很懂这种方式也没关系，后面我还会介绍可视化的UI设计工具

	barNew, _ := gtk.MenuBarNew()
	menuNew, _ := gtk.MenuNew()
	menuOne, _ := gtk.MenuItemNewWithLabel("测试")
	menuTwo, _ := gtk.MenuItemNewWithLabel("测试2")

	barNew.Append(menuOne)
	menuOne.SetSubmenu(menuNew)
	menuNew.Append(menuTwo)

	grid.Attach(barNew, 0, 0, 10, 1)

	appWindow.Add(grid)

	appWindow.ShowAll()
}
